#include "HeartbeatDetectionResponse.h"

HeartbeatDetectionResponse::HeartbeatDetectionResponse() {}

HeartbeatDetectionResponse::HeartbeatDetectionResponse(QString factoryNo, QString transId, QDateTime eventTime, QString resultCode, QString resultMsg) :
    factoryNo(factoryNo),
    transId(transId),
    eventTime(eventTime),
    resultCode(resultCode),
    resultMsg(resultMsg)
{

}

bool HeartbeatDetectionResponse::fromJson(const QByteArray &jsonData)
{
    bool rtn = false;
    QJsonDocument doc = QJsonDocument::fromJson(jsonData);

    if(doc.isNull())
        rtn = false;
    else
    {
        QJsonObject json = doc.object();
        factoryNo = json["factoryNo"].toString();
        transId = json["transId"].toString();
        eventTime = QDateTime::fromString(json["eventTime"].toString());
        resultCode = json["resultCode"].toString();
        resultMsg = json["resultMsg"].toString();
        success = json["resultCode"].toBool();
        if(resultCode == "0")
            rtn = true;
        else
            rtn = false;
    }

    return rtn;
}
